<%-- 
    Document   : FRoutePriceTime
    Created on : 01/05/2010, 12:30:02
    Author     : marcelo
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="br.terminalrodoviario.Route"%>
<%@page import="br.terminalrodoviario.City"%>
<%@page import="br.terminalrodoviario.RouteType"%>
<%@page import="br.terminalrodoviario.RouteItinerary"%>
<%@page import="br.terminalrodoviario.RoutePrice"%>
<%@page import="java.util.*, java.text.*" %>
<jsp:useBean class="br.terminalrodoviario.Route" id="Route" scope="page"/>
<jsp:useBean class="br.terminalrodoviario.Company" id="company" scope="session"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%
            if (company.getId() == 0) {
                response.sendRedirect("../login.jsp");
            }
            String id = request.getParameter("id");
            if (id != null) {
                Route = new Route().selectById("Select r from Route r where r.id = " + id);
            }
%>
<html>
    <head>
        <title>Guia Terminal Rodoviário</title>
        <style type="text/css">
            @import url("../../add/css/company.css");
            @import url("../../add/css/rodape.css");
        </style>
        <script type="text/javascript">
            function putDot(txt){
                txt.value = txt.value.replace(",", ".");
            }
        </script>
    </head>
    <body>
        <div class="geral">
            <table>
                <tr>
                    <td>
                        <div id="cabecalho">
                        </div>
                    </td>
                </tr>
            </table>
            <table id="menuAdmin" width="762">
                <tr >
                    <td align="center">
                        <ul class="menuRota" >
                            <li class="current"><a href="../Manager/MRoute.jsp" /></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuSolicitacao" >
                            <li><a href="../Manager/MSolicitation.jsp" /></li>
                        </ul>
                    </td>
                </tr>
            </table>

            <div style="float:left">
                <br/>
                <b><a href="../index.jsp">Início</a> -> <a href="../Manager/MRoute.jsp">Rotas</a> -> <a href="FRoutePrice.jsp">Preços</a></b>
                <br/><br/>
            </div>
            <div align="right" style="font-family:calibri; font-size:11px; font-style:inherit">
                <br/>Bem-vindo <b><%=request.getSession().getAttribute("username")%></b>,<br/>
                você está logado desde <%=request.getSession().getAttribute("date_session")%>h. ( <a href="../logout.jsp"><b>Logout</b></a> )<br/><br/>
            </div>

            <table  id="subTitulo">
                <tr>
                    <td id="icone">
                        &nbsp;&nbsp;&nbsp;&nbsp;<img src="../../add/images/icones/price.png" alt="Preço" title="Preço"/>
                    </td>
                    <td>
                        Preços
                    </td>
                </tr>
            </table>

            <form id="frm" action="../RoutePriceServlet" method="post">
                <%
                    String ft = "###,##0.00";
                    DecimalFormat myFormatter = new DecimalFormat(ft);
                    DecimalFormatSymbols dfs = new DecimalFormatSymbols(new Locale("pt", "BR"));
                    dfs.setMonetaryDecimalSeparator('.');
                    myFormatter.setDecimalFormatSymbols(dfs);
                %>
                <input type="hidden" name="id" value="<%=id%>"/>
                <%
                            Collection<RouteItinerary> rtCities = new RouteItinerary().select("select rt from RouteItinerary rt where rt.route.id = " + id + " order by rt.sequence asc");
                            Object[] rts = rtCities.toArray();
                %>
                <table cellpadding="0" cellspacing="0">
                    <tr style="height:100px; vertical-align:center; text-align:right;" valign="top">
                        <td width="120" ></td>
                        <td style="white-space:nowrap;-moz-transform:rotate(270.0deg) translate(-40px,0px);-moz-transform-origin:0 100%;width:130px"></td>
                        <%
                                    int i = 0;
                                    //out.println(rts.length);
                                    for (i = 0; i < (rts.length); i++) {
                                        RouteItinerary rt = (RouteItinerary) rts[i];
                        %>
                        <td style="white-space:nowrap;-moz-transform:rotate(270.0deg) translate(-40px,0px);-moz-transform-origin:0 100%;width:185px;"><%=rt.getCity().getFullName()%></td>

                        <%
                                    }
                        %>
                    </tr>
                    <br/><br/>
                    <%
                                for (i = 0; i < (rts.length); i++) {
                                    RouteItinerary rt = (RouteItinerary) rts[i];
                    %>
                    <tr class="<%=(i % 2 != 0) ? "table_row_bg" : "table_row"%>">
                        <td width="270"><%=rt.getCity().getFullName()%></td>
                        <%
                                for (int j = 0; j < (rts.length); j++) {
                                    RouteItinerary rt2 = (RouteItinerary) rts[j];
                        %>
                        <td>
                            <input  type="text" onblur="javascript:putDot(this);" <%=rt.getCity().getId() == rt2.getCity().getId() ? "style='background-color:#CCCCCC;' disabled='true'" : null%> size="5" name="<%=String.valueOf(rt.getCity().getId()) + '-' + String.valueOf(rt2.getCity().getId())%>" id="<%=String.valueOf(rt.getCity().getId()) + '-' + String.valueOf(rt2.getCity().getId())%>"/>
                        </td>
                        <%
                                                            }
                        %>
                    </tr>
                    <%
                                }
                    %>
                </table>
                <br/>
                   <script type="text/javascript">
                    <%
                                if (id != null) {
                                    Object[] rtts = new RoutePrice().select("select rt from RoutePrice rt where rt.route.id=" + Route.getId()).toArray();
                                    for (int j = 0; j < rtts.length; j++) {
                                        RoutePrice price = (RoutePrice) rtts[j];
                                        out.println("document.getElementById('" + price.getCityFrom().getId() + "-"+ price.getCityTo().getId() + "').value='" + price.getPrice() + "';");
                                    }
                                }
                    %>
                </script>
                <table>
                    <tr>
                        <td><input type="submit" value="Gravar"/></td>
                    </tr>
                </table>
                <br/><br/>
            </form>
            <table id="rodape" style="background-image:url(../../add/images/rodape.png);">
                <tr>
                </tr>
            </table>
            <table id="btRodape" style="text-decoration: none;" >
                <tr>
                    <td align="center" width="80px">
                        <ul class="btYoutube">
                            <li><a title="Youtube" href="http://www.youtube.com" /></li>
                        </ul>
                    </td >
                    <td align="center" width="80px">
                        <ul class="btOrkut">
                            <li><a title="Orkut" href="http://www.orkut.com" /></li>
                        </ul>
                    </td>
                    <td align="center" width="205px">
                        <ul class="btTwitter">
                            <li><a title="Twitter" href="http://twitter.com" /></li>
                        </ul>
                    </td>
                    <td align="center">
                        <a title="Trabalhe Conosco" class="text" href="../../Carrer.jsp" >Trabalhe Conosco</a>
                    </td>
                    <td align="center"  width="">
                        <a title="Mapa do Site" class="text" href="../../SiteMap.jsp">Mapa do Site</a>
                    </td>
                    <td align="center" width="">
                        <a title="Contatos" class="text" href="../../Contact.jsp">Contatos</a>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>
